package com.lb.activity.sys.controller;

import com.lb.activity.po.Dictionary;
import com.lb.activity.po.DictionaryData;
import com.lb.activity.sys.service.DictionaryService;
import com.lb.activity.util.ResultUtil;
import com.lb.activity.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 数据字典
 * @author 001030
 */
@RestController
public class DictionaryController {

    @Autowired
    private DictionaryService dictionaryService;

    /**
     * 跳转到数据字典列表页
     * @return
     */
    @GetMapping("dictionary")
    public ModelAndView dictionary(){
        return new ModelAndView("dictionary/dict");
    }


    /**
     * 跳转到数据字典分类
     * @return
     */
    @GetMapping("toDict")
    public Object toDict(){
        return new ModelAndView("dictionary/dictAct");
    }

    /**
     * 数据字典分类分类列表
     * @return
     */
    @GetMapping("dictActs")
    public Object dictActs(PageVo pageVo){
        ResultUtil resultUtil = dictionaryService.dictActs(pageVo);
        return resultUtil;
    }

    /**
     * 分类添加页面
     * @return
     */
    @GetMapping("toDictActAdd")
    public Object todictActAdd(){
        return new ModelAndView("dictionary/dictAct-add");
    }

    /**
     * 添加dictionary操作
     * @param dictionary
     * @return
     */
    @PostMapping("dictActAdd")
    public Object dictActAdd(Dictionary dictionary){
        ResultUtil resultUtil = dictionaryService.addDictionary(dictionary);
        return resultUtil;
    }

    /**
     * 获取dictionary详情
     * @param id
     * @return
     */
    @GetMapping("toModifyDictAct")
    public ModelAndView toModifyDictAct(Long id){
        Dictionary dictionary = dictionaryService.dictionaryById(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("dictionary",dictionary);
        modelAndView.setViewName("dictionary/dictAct-modify");
        return modelAndView;
    }

    /**
     * 更新dictionary
     * @param dictionary
     * @return
     */
    @PostMapping("dictActModify")
    public Object dictActModify(Dictionary dictionary){
        ResultUtil resultUtil = dictionaryService.modifyDictionary(dictionary);
        return resultUtil;
    }

    /**
     * 跳转到添加dictionaryData 界面
     * @return
     */
    @GetMapping("toAddDictData")
    public ModelAndView toAddDictData(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("dictionary/dictData-add");
        //查询分类
        List<Dictionary> dictionaries = dictionaryService.dictActs();
        modelAndView.addObject("dictionaries",dictionaries);
        return modelAndView;
    }

    /**
     * 添加
     * @param dictionaryData
     * @return
     */
    @PostMapping("dictDataAdd")
    public ResultUtil dictDataAdd(DictionaryData dictionaryData){
        ResultUtil resultUtil = dictionaryService.addDictionaryData(dictionaryData);
        return resultUtil;
    }

    /**
     * dictionary data 列表
     * @param pageVo
     * @return
     */
    @GetMapping("dictDatas")
    public Object dictDatas(PageVo pageVo){
        ResultUtil resultUtil = dictionaryService.dictDatas(pageVo);
        return resultUtil;
    }

    /**
     * 删除数据
     * @param id
     * @return
     */
    @PostMapping("removeDictData")
    public ResultUtil removeDictData(Long id){
        ResultUtil resultUtil = dictionaryService.delDictData(id);
        return resultUtil;
    }

    /**
     * 页面跳转
     * @param id
     * @return
     */
    @GetMapping("modifyDictData")
    public ModelAndView modifyDictData(Long id){
        DictionaryData data = dictionaryService.dictionaryDataById(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("dictionaryData",data);
        modelAndView.setViewName("dictionary/dictData-modify");
        return modelAndView;
    }

    /**
     * 修改 dictionary data
     * @param dictionaryData
     * @return
     */
    @PostMapping("dictDataUpdate")
    public Object dictDataUpdate(DictionaryData dictionaryData){
        ResultUtil resultUtil = dictionaryService.updateDictionaryData(dictionaryData);
        return resultUtil;
    }




}
